import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";

/**
 * 对集合操作的方法
 * @creationDate 2019/12/30
 */

/**
 * 遍历并转化树
 */
export function mapTree(tree, iter, options) {
  return (tree || []).map(function (item) {
    var _ref = options || {},
        _ref$childrenName = _ref.childrenName,
        childrenName = _ref$childrenName === void 0 ? 'children' : _ref$childrenName,
        parent = _ref.parent,
        _ref$childrenNullable = _ref.childrenNullable,
        childrenNullable = _ref$childrenNullable === void 0 ? false : _ref$childrenNullable;

    var tran = iter(item, parent);

    if (tran[childrenName] || !childrenNullable) {
      tran[childrenName] = mapTree(tran[childrenName] || [], iter, _objectSpread(_objectSpread({}, options), {}, {
        parent: tran
      }));
    }

    return tran;
  });
}